class PicdataController < ApplicationController

  # GET
  def index

    return unless checkAdmin

  	@piclist = Picdata.paginate(:page => params[:page]).order("id DESC")

  	@picdata = Picdata.new
    render :template => 'admin/picdata.html.erb'
  end

  # POST
  def create
  	@picdata = Picdata.create( params[:picdata] )
  	if(@picdata.save)
  		flash[:result] = 'upload success'
	else
		flash[:result] = 'upload failure'
  	end
  	redirect_to '/admin/picdata'
  end

  # DELETE
  def delete
  	_success = false
  	@picdata = Picdata.find(params[:id])
  	if(@picdata != nil)
  		#@picdata.pic = nil
  		_success = @picdata.destroy
  	end
  	render :text => if(_success) then 1 else 0 end
  end

end
